﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConfigMeister
{
    static class MaterialBucket
    {
        private static List<Material> _list;

        static MaterialBucket()
        {
            _list = new List<Material>();
        }

        public static int Count
        {
            get { return _list.Count; }
        }

        public static string GenericName
        {
            get
            {
                string tempName = "Material0";
                for (int i = 0; i <= _list.Count; i++)
                {
                    tempName = "Material" + Convert.ToString(i);
                    bool found = false;
                    foreach (Material val in _list)
                    {
                        if (val.Name == tempName)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found) continue;
                    break;
                }

                return tempName;
            }
        }

        public static void Add(Material mat)
        {
            _list.Add(mat);
        }

        public static void Remove(string name)
        {
            for (int i = 0; i < Count; i++)
            {
                if (_list[i].Name == name)
                {
                    _list.RemoveAt(i);
                    return;
                }
            }
        }

        public static Material Get(string name)
        {
            if(Count == 0)
            {
                return new Material();
            }

            foreach (Material v in _list)
                if (v.Name == name)
                    return v;

            return new Material();
        }

        public static void Modify(string name, Material mod)
        {
            for(int i=0; i<Count; i++)
            {
                if(_list[i].Name == name)
                {
                    _list[i] = mod;
                    return;
                }
            }
        }

        public static string[] GetList()
        {
            string[] temp = new string[Count];

            for (int i=0; i<Count; i++)
            {
                temp[i] = _list[i].Name;
            }

            return temp;
        }
    }
}
